package com.ysq.www.api.work.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysq.www.api.work.entity.ReplyAll;
import com.ysq.www.api.work.mapper.ReplyAllMapper;
import com.ysq.www.api.work.service.IReplyAllService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 待办整合 服务实现类
 * </p>
 *
 * @author dql
 * @since 2020-08-11
 */
@Slf4j
@Service
public class ReplyAllServiceImpl extends ServiceImpl<ReplyAllMapper, ReplyAll> implements IReplyAllService {

    @Autowired
    private ReplyAllMapper replyAllMapper;

    /**
     * 查询所有我发起的待办
     * @param userId 用户id
     * @param time 日期
     * @param pageNumber 页码
     * @param pageSize 页大小
     * @return IPage
     */
    @Override
    public IPage<ReplyAll> selectMyAllById(Integer userId, String time, Integer pageNumber, Integer pageSize) {
        Page<ReplyAll> page = new Page<>(pageNumber,pageSize);
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        if (!StringUtils.isEmpty(time)){
            String startTime = time + " 00:00:00";
            String endTime = time + " 23:59:59";
            map.put("startTime",startTime);
            map.put("endTime",endTime);
        }
        IPage<ReplyAll> rPage = replyAllMapper.selectMyAllById(page,map);
        return rPage;
    }

    /**
     * 查询处理/待处理的待办
     * @param userId 用户id
     * @param time 日期
     * @param type 类型：0未处理，1已处理
     * @param pageNumber 页码
     * @param pageSize 页大小
     * @return IPage
     */
    @Override
    public IPage<ReplyAll> selectPendingByPage(Integer userId, String time, Integer type, Integer pageNumber, Integer pageSize) {
        Page<ReplyAll> page = new Page<>(pageNumber,pageSize);
        IPage<ReplyAll> rPage = null;
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("type",type);
        if (!StringUtils.isEmpty(time)){
            String startTime = time + " 00:00:00";
            String endTime = time + " 23:59:59";
            map.put("startTime",startTime);
            map.put("endTime",endTime);
        }
        if (type == 0){
            rPage = replyAllMapper.selectNotPendingByPage(page,map);
        }else if (type == 1){
            rPage = replyAllMapper.selectPendingByPage(page,map);
        }
        return rPage;
    }
}
